<template>
  <div class="video-card" @click="toPlay" >
    <el-card class="el-card" :body-style="{ padding: '0px' }" shadow="hover">
      <div class="pic">
        <img :src="baseUrl+mySrc" class="image">
        <div class="vip" v-if="video.isVip==1">
          <img src="../img/vip.png" alt="">
        </div>
      </div>
      <div class="text-box">
        <div style="padding: 2px;" class="title">
          <span>{{mytitle}}</span>
        </div>
        <div class="digest">
          <p class="play">
            <i class="el-icon-view"></i>
            {{myPlayNum}}
          </p>
          <p class="time">
            <i class="el-icon-time"></i>
            {{mytime}}
          </p>
        </div>
        <div class="author">up: {{myUp}}</div>
      </div>
    </el-card>
  </div>
</template>
<script>
export default {
  props: ["src", "title", "play", "up", "time", "id", "nojump", "isVip","video"],
  name: "video-card",
  data: function() {
    return {
      baseUrl: this.GLOBAL.baseFilePath
    };
  },
  methods: {
    toPlay: function() {
      this.axios
        .post("video/isPlay", {
          userId: this.userId,
          videoId: this.id?this.id:this.video.id
        })
        .then(res => {
          if (!res.data.isPlay) {
            this.toOpenVip();
            return;
          }
          let routeData = this.$router.resolve({
            name: "play",
            query: { id: this.id?this.id:this.video.id }
          });
          window.open(routeData.href, "_blank");
        });
    },
    //跳转到vip开通界面
    toOpenVip() {
      this.$confirm("此视频只有vip会员才能观看，是否开通vip?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          let routeData = this.$router.resolve({
            name: "vipOpen",
            query: { id: this.id }
          });
          window.open(routeData.href, "_blank");
        })
        .catch(() => {});
    }
  },
  computed:{
    mytime:function(){
      if(this.time) return this.time.substring(0,10);
      if(this.video.uploadTime) return this.video.uploadTime.substring(0,10);
      return ''
    },
    mytitle:function(){
      if(this.title) return this.title;
      if(this.video.title) return this.video.title;
      return ''
    },
    myPlayNum:function(){
      if(this.play!=undefined) return this.play;
      if(this.video.playNum) return this.video.playNum
      return 0
    },
    myUp:function(){
      if(this.up) return this.up;
      if(this.video.userName) return this.video.userName;
      return ''
    },
    mySrc:function(){
      if(this.src) return this.src;
      if(this.video.coverPhoto) return this.video.coverPhoto;
      return ''
    },
    userId:function(){
      return this.$store.state.user?this.$store.state.user.id:''
    }
  }
};
</script>

<style lang="scss" scoped>
img {
  height: 100%;
  width: 100%;
}
.el-card {
  max-width: 170px;
  max-height: 210px;
  font-size: 12px;
  text-align: center;
  cursor: pointer;
  .text-box {
    padding: 0px 10px;
  }
  .pic {
    width: 170px;
    height: 100px;
    position: relative;
    .vip{
      height: 20px;
      width: 20px;
    }
  }
  .title {
    height: 30px;
    overflow: hidden;
    word-break: break-all;
    word-wrap: break-word;
  }
  .digest {
    display: flex;
    justify-content: space-between;
    line-height: 20px;
    p {
      margin: 0;
    }
  }
  .author {
    text-align: left;
    margin: 0px 0px 8px 0px;
  }
}
</style>